#include "t_block.h"

t_block::t_block(int posy, int posx)
{
    //Initialize matrix (T-Position)
    for(int i=0; i<4; i++)
    {
        for(int j=0; j<4; j++)
        {
            if(((i==1) && ((j>=0)&&(j<=2))) || (i==2 && j==1))
                m_pos_matrix[i][j] = true;
            else
                m_pos_matrix[i][j] = false;
        }
    }

    //Initialize state, position and color
    m_state = S_DOWN;
    m_position[0] = posy+1;
    m_position[1] = posx-1;
    m_color = C_YELLOW;

}


t_block::~t_block()
{
    //dtor
}

void t_block::m_Rotate()
{
    switch(m_state)
    {
        case S_DOWN:
        {
            m_state=S_LEFT; //Change block state

            //Just update necessary positions
            m_pos_matrix[1][2] = false;
            m_pos_matrix[0][1] = true;

            break;
        }

        case S_LEFT:
        {
            m_state=S_UP; //Change block state

            //Just update necessary positions
            m_pos_matrix[2][1] = false;
            m_pos_matrix[1][2] = true;

            break;
        }

        case S_UP:
        {
            m_state=S_RIGHT; //Change block state

            //Just update necessary positions
            m_pos_matrix[1][0] = false;
            m_pos_matrix[2][1] = true;

            break;
        }

        case S_RIGHT:
        {
            m_state=S_DOWN; //Change block state

            //Just update necessary positions
            m_pos_matrix[0][1] = false;
            m_pos_matrix[1][0] = true;

            break;
        }


    }
}
